package com.zhongge.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Predicate;

/**
 * @ClassName RemoveTest
 * @Description TODO 删除测试
 * @Author 李明忠
 * @Date 2025/6/13 19:40
 * @Version 1.0
 */
public class RemoveTest {
    public static void main(String[] args) {
        //创建对象
        Collection c1 = new ArrayList();

        //添加元素
        c1.add(123);
        c1.add(1245);
        c1.add("Lihua");

        System.out.println("删除前 " + c1);

        //删除元素
        System.out.println("删除1234 " + c1.remove(1234));
        System.out.println("删除1234 " + c1.remove(1234));
        System.out.println("删除123 " + c1.remove(123));

        System.out.println("删除后 " + c1);

        System.out.println("================================");


        //根据条件来删除 removeIf

        Collection c2 = new ArrayList();

        c2.addAll(c1);

        System.out.println(c2);

        System.out.println("根据条件来删除所有String的元素 " + c2.removeIf(new Predicate() {
            @Override
            public boolean test(Object t) {
                return t instanceof String; //如果是String类型就删除即可
            }
        }));

        System.out.println(c2);
    }
}
